'''
Created on Apr 2, 2013

@author: kevinbauer
'''

import numpy as np

class NeuralNetwork(object):

    def __init__(self, v):
        self.LR = np.float(0.05) # LR is the learning rate.
        self.values = v

    def hypothesize(self):
        # To get the stoppers for the inner while-loops.
        shape = np.shape(self.values)
        rows = shape[0] 
        columns = shape[1]
        
        # Set the initial weights to 0.
        weights = []
        w = 0
        while w < columns:
            weights.append(0.0)
            w += 1
            
        # Convert to a numpy array.
        weights = np.array(weights)
        
        COUNTER = 0
        STOP = 3
        
        # The outer weight adjustment loop.
        while COUNTER < STOP:
            i = 0
            
            while i < rows:
                j = 0
                temp = []
                
                # Get the products of the weights and values of each node.
                while j < columns:
                    temp.append(self.values[i,j] * weights[j])
                    j += 1
                #print temp
                
                # Sum the products to get the activation function.
                input = np.sum(temp)
                input = np.float(input)
#                print input
                
                error = None
                
                desiredOutput = self.values[i,41] # 1 for attack, 0 for normal.
                
                #Activation function. 1 is the threshold.
                if input != desiredOutput:
                    if input > 0.5:
                    #We don't adjust the weights if there is no error.
                        error = desiredOutput - 1.0
                    else:
                        error = desiredOutput - 0.0

                    k = 0
                    while k < columns:
                        weights[k] = self.LR * error * self.values[i, k]
                        k += 1
                    
                # Counter for the first nested while-loop.
                i += 1
            
            # Outermost while-loop counter.
            COUNTER += 1
            
        return weights
        